#!/bin/bash

if [[ -z "${COLCON_PREFIX_PATH}" ]]; then
    echo "错误：环境变量 COLCON_CURRENT_PREFIX 未设置"
    exit 1
fi
 
# 获取并打印环境变量值
current_prefix="${COLCON_PREFIX_PATH}"
echo "COLCON_PREFIX_PATH 的值是: ${current_prefix}"

# 定义脚本名称和路径
SCRIPT_NAME="lib/rcl_logging_spdlog/logconfig.py"
SCRIPT_PATH="${current_prefix}/${SCRIPT_NAME}"

# 检查Python3是否安装
if ! command -v python3 &> /dev/null
then
    echo "错误：未找到python3，请先安装Python3"
    exit 1
fi

# 检查脚本文件是否存在
if [ ! -f "${SCRIPT_PATH}" ]; then
    echo "错误：找不到脚本文件 ${SCRIPT_PATH}"
    exit 1
fi

# 执行Python脚本
echo "正在执行脚本: ${SCRIPT_PATH}"
python3 "${SCRIPT_PATH}"

# 检查执行结果
if [ $? -eq 0 ]; then
    echo "脚本执行成功"
else
    echo "脚本执行失败，请检查错误信息"
    exit 1
fi